const fs = require("fs")

// const reader = fs.createReadStream('./input.txt')

// const writer = fs.createWriteStream('./output.txt')


// //pipe管道流，将一个文件内容读取并存入另一个文件中
// reader.pipe(writer)

//异步写入
fs.writeFile('./input.txt','有志者事竟成',err => {
    if(err){
        console.log('写入失败')
        return
    }
    console.log('写入成功')
})
fs.appendFile('./input.txt','\r\n确实是的',err => {
    if (err) {
        console.log('写入失败~')
        return
    }
    console.log('写入成功~')
})

//同步写入
fs.writeFileSync('./output.txt','哈哈哈哈')
//追加写入
fs.appendFileSync('./output.txt','很高兴认识你')

//__dirname:文件所在目录的绝对路径
fs.writeFileSync(__dirname + '/lujin.txt','shdhsdhsh')
